--- 查询此用户是否已经秒杀过
if( redis.call('exists', KEYS[2]) == 0) then
    redis.call('set',KEYS[2],ARGV[1])
else
    return 2
end

--- 预存库存

if( redis.call('exists', KEYS[1]) == 0) then
    redis.call('set',KEYS[1],ARGV[1])
end
--- 修改库存

local key = KEYS[1]
local oldNum = redis.call('get',key)
if(tonumber(oldNum) > 1) then
    redis.call('set',key,tonumber(oldNum)-1);
    return 1
else
    return 0
end